home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / pp.arc / SPACDEL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-04-07  |  3.5 KB  |  153 lines

  1.  
  2. Program SPACeDELeter;
  3.  
  4. {     Written by James A. Grettum
  5. .                1321 So. 23rd St., Suite A
  6. .                PO Box 7055
  7. .                Fargo, ND 58103
  8. .                (701)293-6646
  9. .
  10. .     Purpose    to DELete unwanted leading spaces from a text
  11. .                file.  The program prompts the user for the maximum
  12. .                number of leading spaces to delete.  This may come
  13. .                in very handy for using PP.COM.
  14. .
  15. .     Started    April 6, 1985
  16. .
  17. .     Last
  18. .     Update     April 7, 1985
  19. .
  20. .
  21. }
  22.  
  23. Var 
  24.   InFile,
  25.   OutFile         :      Text[$800];
  26.   Line,
  27.   Answer          :      string[240];
  28.   I,N,
  29.   NumLines,
  30.   MaxDelete,
  31.   Scrnclr         :      Integer;
  32.   StillSpace,
  33.   FileFound       :      Boolean;
  34.   NameInFile,
  35.   NameOutFile     :      String[20];
  36.  
  37. Procedure OpenInFile;    {Procedure to check for Input File}
  38. Begin
  39.   Repeat
  40.     Gotoxy(10,7);
  41.     Write('Enter the name of the Input file : ');
  42.     ReadLn(NameInFile);
  43.     Gotoxy(10,8);
  44.     ClrEol;
  45.     Assign(Infile,NameInFile);
  46. {$I-}
  47.     Reset(InFile) {$I+} ;
  48.     FileFound := (IOresult = 0);
  49.     If not FileFound
  50.       then
  51.         begin
  52.           Gotoxy(10,8);
  53.           sound(440);
  54.           Delay(500);
  55.           Nosound;
  56.           Write('CANNOT FIND FILE "',NameInFile,'" Try another name.');
  57.         end;
  58.   Until FileFound;
  59. End;
  60.  
  61. Procedure CheckOutFile;    {Procedure to check for OutputFile}
  62. Begin
  63.   Repeat
  64.     Gotoxy(10,9);
  65.     Write('Enter the name for the output file: ');
  66.     ReadLn(NameOutFile);
  67.     Gotoxy(10,10);
  68.     ClrEol;
  69.     Assign(OutFile,NameOutFile);
  70. {$I-}
  71.     Reset(OutFile) {$I+} ;
  72.     FileFound := (IOresult = 0);
  73.     If FileFound
  74.       then
  75.         begin
  76.           Gotoxy(10,10);
  77.           sound(440);
  78.           Delay(500);
  79.           Nosound;
  80.           Close(OutFile);
  81.           Write('That file already exists!! Continue? (y): ');
  82.           Read(Answer);
  83.           If Upcase(Answer)='Y'
  84.             then FileFound := False;
  85.         end;
  86.   Until not FileFound;
  87. End;
  88.  
  89. begin
  90.   ClrScr;
  91.   TextBackground(7);
  92.   TextColor(0);
  93.   Gotoxy(28,1);
  94.   Write(' SPACe DELeter ');
  95.  
  96.   Gotoxy(10,3);
  97.   Write('    This program will delete unwanted leading     ');
  98.   Gotoxy(10,4);
  99.   Write('  spaces in a text file. You can set the maximum  ');
  100.   Gotoxy(10,5);
  101.   Write('             spaces to be deleted.                ');
  102.   NormVideo;
  103.   OpenInFile;
  104.   CheckOutFile;
  105.   Gotoxy(10,11);
  106.   Write('Enter the maximum number of spaces to delete: ');
  107.   ReadLn(MaxDelete);
  108.   Reset(InFile);
  109.   Assign(OutFile,NameOutFile);
  110.   Rewrite(OutFile);
  111.   Gotoxy(10,13);
  112.   Write('The Input file is  ' + NameInFile);
  113.   Gotoxy(10,15);
  114.   Write('The Output file is ' + NameOutFile);
  115.   Gotoxy(10,17);
  116.   Write('Working on Line: ');
  117.   WriteLn(' ');
  118.   Scrnclr := 0;
  119.   NumLines := 0;
  120.  
  121.   while not EOF(InFile) do
  122.     begin
  123.  
  124.       ReadLn(InFile,Line);
  125.       Numlines := Numlines + 1;
  126.       N := 0;
  127.       StillSpace := True;
  128. {WriteLn(Line);}
  129.       While StillSpace Do
  130.         Begin
  131.           I := N+1;
  132.           If Line[I]=' '
  133.             then
  134.               begin
  135.                 N := N+1;
  136.                 if n=maxdelete
  137.                   then
  138.                     StillSpace := False;
  139.               end
  140.             Else StillSpace := False;
  141.         end;
  142.       DELETE(Line,1,N);
  143.       GotoXY(28,17);
  144.       WriteLn(NumLines);
  145.       WriteLn(OutFile,Line);
  146.     end;
  147.  
  148.   WriteLn(' ');
  149.   WriteLn('All Done');
  150.   Close(InFile);
  151.   Close(OutFile);
  152. end.
  153.